#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int maxSubarraySumCircular(vector<int>& nums) {
        int sum = 0;
        for (auto e : nums) sum += e;

        vector<int> dp1(nums.begin(), nums.end());
        vector<int> dp2(nums.begin(), nums.end());

        for (int i = 1; i < nums.size(); i++)
        {
            dp1[i] = max(dp1[i], dp1[i] + dp1[i - 1]);
            dp2[i] = min(dp2[i], dp2[i] + dp2[i - 1]);
        }

        int Max = dp1[0];
        int Min = dp2[0];

        for (int i = 1; i < nums.size(); i++)
        {
            Max = max(Max, dp1[i]);
            Min = min(Min, dp2[i]);
        }

        // return max(Max, sum - Min) == 0 ? Max : max(Max, sum - Min);
        return sum == Min ? Max : max(Max, sum - Min);
    }
};